package com.applink.sell_proof.builder;

import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.applink.sell_proof.AbstractActivity;
import com.applink.sell_proof.R;

public class PopupBuilder extends AbstractListBuilder {
	private AbstractActivity abstractActivity;
	public PopupBuilder(Context context, ViewGroup parent) {		
		super(context, parent);
	}

	@Override
	public void notifyDataChange() {
		mAdapter.notifyDataSetChanged();
	}

	@Override
	public View buildConvertView() {
		View layout = mLayoutInflater.inflate(R.layout.popupitem, null);
		return layout;
	}

	@Override
	public ConcurrentHashMap<Integer, View> buildConvertViewContent(View base) {
		ConcurrentHashMap<Integer, View> views = new ConcurrentHashMap<Integer, View>();
		views.put(R.id.popupitem, base.findViewById(R.id.popupitem));
		return views;
	}

	@Override
	public void builConvertViewContentData(int position, ConcurrentHashMap<Integer, View> views, List<? extends Object> data) {

		@SuppressWarnings("unchecked")
		final HashMap<String, String> map = (HashMap<String, String>) data.get(position);

		TextView v = ((TextView) views.get(R.id.popupitem));

		v.setText(map.get("title"));

		v.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Intent intent = null;
				try {					
					if(map.get("className")!= null && (!map.get("className").equals(map.get("classShowing")))){						
						intent = new Intent(mContext, Class.forName(map.get("className")));
					}					
				} catch (ClassNotFoundException e) {
					e.printStackTrace();
				}

				if (intent != null)
					mContext.startActivity(intent);
			}
		});
	}

	public ListView getListView() {
		return mListView;
	}
}
